﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DAL;
using Model;

namespace BLL
{
    public class HouseHolderManage
    {
        public static HouseHolder AddHouseHolder(HouseHolder hHolder)
        {
            return HouseHolderService.AddHouseHolder(hHolder);
        }

        public static int GetPersonalInformationIdById(int id)
        {
            return HouseHolderService.GetPersonalInformationIdById(id);
        }

        public static List<HouseHolder> GetHouseHoldersNotChecked()
        {
            return HouseHolderService.GetHouseHoldersNotChecked();
        }

        public static List<HouseHolder> GetHouseHoldersChecked()
        {
            return HouseHolderService.GetHouseHoldersChecked();
        }

        public static HouseHolder GetHouseHolderByPersonalInformationId(int pId)
        {
            return HouseHolderService.GetHouseHolderByPersonalInformationId(pId);
        }

        public static int GetIdByPersonalInformationId(int pId)
        {
            HouseHolder hHolder = HouseHolderService.GetHouseHolderByPersonalInformationId(pId);
            if (hHolder == null)
                return -1;
            else
                return hHolder.Id;
        }

     
        public static void Checked(int UserId, int check)
        {
            HouseHolder hHolder = HouseHolderService.GetHouseHolderById(UserId);
            hHolder.IsChecked = check;
            HouseHolderService.UpdateHouseHolder(hHolder);
        }

        public static List<HouseHolder> GetAllHouseHolders()
        {
            return HouseHolderService.GetAllHouseHolders();
        }

        public static void Recommend(int id, bool check)
        {
            if (!HouseHolderService.HasId(id))
                return;

            HouseHolder hHolder = HouseHolderService.GetHouseHolderById(id);
            hHolder.IsRecommended = Convert.ToInt32(check);
            HouseHolderService.UpdateHouseHolder(hHolder);
        }

        public static void Rating(int id, int rate)
        {
            if (!HouseHolderService.HasId(id))
                return;

            HouseHolder hHolder = HouseHolderService.GetHouseHolderById(id);
            hHolder.EvaluationScore = rate;
            HouseHolderService.UpdateHouseHolder(hHolder);
        }

        private static HouseHolder GetHouseHolderById(int id)
        {
 	        return HouseHolderService.GetHouseHolderById(id);
        }


        public static bool IsChecked(int id)
        {
            HouseHolder hHolder = GetHouseHolderById(id);
            if (hHolder == null)
                return false;
            return Convert.ToBoolean(hHolder.IsChecked);
        }

        public static bool HasId(int userId)
        {
            if (HouseHolderService.GetHouseHolderById(userId) != null)
                return true;
            else
                return false;
        }
    }
}
